<?php


namespace app\api\epay;

require_once "lib/epay_submit.class.php";
require_once "lib/epay_notify.class.php";
class EpayApi
{
	public static function getPayHtml($config, $out_trade_no, $money, $name, $type, $notify_url, $return_url)
	{
		$alipay_config["partner"] = $config["id"];
		$alipay_config["key"] = $config["key"];
		$alipay_config["sign_type"] = strtoupper("MD5");
		$alipay_config["input_charset"] = strtolower("utf-8");
		$alipay_config["transport"] = "http";
		$alipay_config["apiurl"] = $config["url"];
		$sitename = "易支付测试站点";
		$parameter = ["pid" => trim($alipay_config["partner"]), "type" => $type, "notify_url" => $notify_url, "return_url" => $return_url, "out_trade_no" => $out_trade_no, "name" => $name, "money" => $money, "sitename" => $sitename];
		$alipaySubmit = new \AlipaySubmit($alipay_config);
		$html_text = $alipaySubmit->buildRequestForm($parameter);
		return "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
            <html>
            <head>
                <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
                <title>正在跳转支付中...</title>
            </head><body>" . $html_text . "</body></html>";
	}
	public static function verifySign($config)
	{
		$alipay_config["partner"] = $config["id"];
		$alipay_config["key"] = $config["key"];
		$alipay_config["sign_type"] = strtoupper("MD5");
		$alipay_config["input_charset"] = strtolower("utf-8");
		$alipay_config["transport"] = "http";
		$alipay_config["apiurl"] = $config["url"];
		$alipayNotify = new \AlipayNotify($alipay_config);
		$verify_result = $alipayNotify->verifyNotify();
		if ($verify_result) {
			return true;
		} else {
			return false;
		}
	}
}